<?php

class ShiftChangeController extends Controller
{

	public function behaviors() {
		return array(
			'exportableGrid' => array(
				'class' => 'application.components.ExportableGridBehavior',
				'filename' => 'ShiftChange_Swap_Report_Results.csv',
				'csvDelimiter' => ',', 
				));
	}

	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/column3';
	public $sidebarMenu=array(
							array('label'=>'My Shifts', 'url'=>array('/shift/my_shifts')),
							array('label'=>'Team Shifts', 'url'=>array('/shift/team_shifts')),
							array('label'=>'Shift Changes', 'url'=>array('/shiftChange/change_management')),
							);

	protected function beforeAction($action) {
		if(!(Yii::app()->user->isGuest)) {
			$this->links =  Links::getTeamLinks(Yii::app()->user->team_id);
			
			if(empty($this->links)) {
				$this->links = array(array('label'=>'---','url'=>'#'));
				return true;
			} else
				return true;
		}
		else
			return true;
	}
	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			'postOnly + delete', // we only allow deletion via POST request
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index','view'),
				'users'=>array('@'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('create','cancel','change_management','ajaxTargetShiftLoader','shortView','swap_management','viewSwap','cancelSwap'),
				'users'=>array('@'),
			),
			array('allow', 
				'actions'=>array('reporting','management','managementView','approve','deny','rosterCreate','rosterCreateEmpty',
								 'ajaxEditComments','ajaxUpdateComments','ajaxMembersView','ajaxRosterCreate','accountingApprovals','accountingApprove'
								 ),
				'users'=>array('@'),
				'expression'=>'$user->can_edit_shift_change == 1',
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
	/**
	 * Displays a particular model.
	 * @param integer $id the ID of the model to be displayed
	 */
	public function actionView($id)
	{
		$this->render('view',array(
			'model'=>$this->loadModel($id),
		));
	}

	public function actionShortView($id)
	{
		$this->sidebarMenu=array(
								array('label'=>'Team Q-Shifts', 'url'=>array('/qshift/team_Qshifts' , 'team'=>Yii::app()->user->team_id)),
								array('label'=>'My Q-Shifts', 'url'=>array('/qshift/my_qshifts')),
								array('label'=>'Swap Q-Shift', 'url'=>array('/qshift/swap')),
								array('label'=>'Swap Management', 'url'=>array('/shiftchange/swap_management')),
								);		
		$this->render('shortView',array(
			'model'=>$this->loadModel($id),
		));
	}

	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		$model=new ShiftChange;

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);
		
		$model->requesting_user = User::model()->findByAttributes(array('username'=>Yii::app()->user->id))->iduser;
		$model->team_id = Yii::app()->user->team_id;
		$model->request_status = ShiftChange::STATUS_PENDING;

		if(isset($_POST['ShiftChange']))
		{
			$model->attributes=$_POST['ShiftChange'];		
			
			$currentShift = Schedule::getUserScheduleForDate($model->requesting_user, $model->day_requested);
			
			if($currentShift!=null)
				$model->current_shift = $currentShift->idshift;
			
			//print_r($_POST); 
			
			if(isset($_POST['choice']) and ($_POST['choice'] == 'radioToShift')) {

				// start active shift change check
				$criteria=new CDbCriteria;
				$criteria->condition = "day_requested like '".$model->day_requested."' \n
										and (request_status <> ". ShiftChange::STATUS_CANCELLED ." and request_status <> ". ShiftChange::STATUS_DENIED.") \n
										and (requesting_user = '".$model->requesting_user."')";			
				
				$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
				
				//print_r($shiftChangeResult);exit;
				
				// checking if user already has shift change pending or approved for this day
				if ($shiftChangeResult!=null) {
					$model->addError('requested_shift','You already have a change pending or approved for this day, only one allowed!');
					$this->render('create',array(
						'model'=>$model,
					));					
				} else {			
					$model->target_user = null;
					
					//Check if Shift requires Accounting approval
					if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
						$model->require_acct_approval = 1;					
					
					//all checks passed, save!
					if($model->save()){
						
						//send email notification to requestor
						$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
						
						//send email notification to target_user if present
						if($model->target_user != null)
							$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);						
						
						$this->redirect(array('view','id'=>$model->idshift_change));
						
					} else {
						$model->addError('day_requested','Error saving!');
					
						$this->render('create',array(
							'model'=>$model,
						));
					}
				}			
			
			} else if(isset($_POST['choice']) and ($_POST['choice'] == 'radioToUser') ) {
			
				if( empty($_POST['ShiftChange']['target_user']) ) {
					$model->addError('target_user','A "Target User" must be selected if the "Change with User" option is used!');	
					
					$this->render('create',array(
						'model'=>$model,
					));					
				} else {

					// start active shift change check
					$criteria=new CDbCriteria;
					$criteria->condition = "day_requested like '".$model->day_requested."' \n
											and (request_status <> ". ShiftChange::STATUS_CANCELLED ." and request_status <> ". ShiftChange::STATUS_DENIED.") \n
											and (requesting_user = '".$model->requesting_user."' or target_user = '".$model->requesting_user."'
												or requesting_user = '".$model->target_user."' or target_user = '".$model->target_user."')";			
					
					$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
					
					// checking if user already has shift change pending or approved for this day
					if ($shiftChangeResult!=null) {
						$model->addError('day_requested','You, or the target user, already have a change pending or approved for this day, 
															and only one allowed per user per day!');
						$this->render('create',array(
							'model'=>$model,
						));					
					} else {	
					
						//Check if Shift requires Accounting approval
						if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
							$model->require_acct_approval = 1;					
					
						//all checks passed, save!
						if($model->save()){
							
							
							//send email notification to requestor
							$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
							
							//send email notification to target_user if present
							if($model->target_user != null)
								$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);
							
							$this->redirect(array('view','id'=>$model->idshift_change));
							
						} else {
							$model->addError('day_requested','Error saving with target user!');
						
							$this->render('create',array(
								'model'=>$model,
							));
						}
					}
				}
			} else
				echo "NO IF MATCHED!"; exit;
			
		}

		$this->render('create',array(
			'model'=>$model,
		));
	}

	public function actionAjaxTargetShiftLoader(){
		
		//print_r($_GET);exit;
		$target_user = $_GET['target_user'];
		$date = $_GET['date'];
		
		if ($target_user == null) {
			echo " ";
			exit;
		}
		
		if ($date == null){
			echo "<span class='errorMessage'>You must select a date first! </span>";
			echo '<img src="'.Yii::app()->theme->baseUrl.'/images/hr.gif" 
					   onload="cleanDropdown(\'ShiftChange_target_user\');"
					   width=10px>';			
			exit;
		}
		
		$criteria=new CDbCriteria;
		$criteria->condition = "day_requested like '".$date."' \n
								and (request_status <> ". ShiftChange::STATUS_CANCELLED ." or request_status <> ". ShiftChange::STATUS_DENIED.") \n
								and (requesting_user = '".$target_user."' or target_user = '".$target_user."')";
		
		$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
		
		if ($shiftChangeResult!=null) {
			echo "<span class='errorMessage'>The target user already has a shift change approved or pending for this date. Change not allowed!</span>";
			exit;
		} 
		
		$scheduleModel = Schedule::getUserScheduleForDate($target_user, $date);
		
		if($scheduleModel == null){
			echo "<span class='errorMessage'>This user doesn't have a schedule assigned for that day of the week!</span>";
		} else {
			// Echo textfields with information
			//echo "schedule id = " . $scheduleModel->idschedule;exit;
			echo CHtml::label('Target Shift and Q-Shift','txt_target_qshift');
			echo CHtml::textField( 'txt_target_shift',$scheduleModel->shift_relation->name ,array('size'=>15,'readonly'=>true)) ;
			echo CHtml::textField( 'txt_target_qshift',$scheduleModel->qshift_relation->name ,array('size'=>15,'readonly'=>true)) ;		
			echo '<img src="'.Yii::app()->theme->baseUrl.'/images/checked.png" 
					   onload="setRequestedShiftQshift('.$scheduleModel->idshift.',
													   '.$scheduleModel->idqshift.')"
					   width=2px">';
		}
		
	}
	

	public function actionUpdate($id)
	{
		$model=$this->loadModel($id);

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['ShiftChange']))
		{
			$model->attributes=$_POST['ShiftChange'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->idshift_change));
		}

		$this->render('update',array(
			'model'=>$model,
		));
	}

	public function actionCancel($id)
	{
		$model = $this->loadModel($id);
		
		if ($model->request_status == ShiftChange::STATUS_PENDING) {
		
			$model->request_status = ShiftChange::STATUS_CANCELLED;
			$model->comments .= "... Change Request Cancelled by " . Yii::app()->user->id;
			
			if(!$model->save(false)){
				
				throw new CHttpException(400,'Error saving data for shift change cancel action... contact michamen@cisco.com!');
			} else {
				
				//send email notification to requestor
				$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
				
				//send email notification to target_user if present
				if($model->target_user != null)
					$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);				
			
				// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
				if(!isset($_GET['ajax']))
					$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('view', 'id'=>$id));	
			}
		} else if ($model->request_status == ShiftChange::STATUS_APPROVED) {
		
			$model->request_status = ShiftChange::STATUS_PENDING_CANCEL;
			//echo "entered here";
			if(!$model->save(false)){
			
				throw new CHttpException(400,'Error saving data for shift change cancel action... contact michamen@cisco.com!');
				
			} else {
				//send email notification to requestor
				$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
				
				//send email notification to target_user if present
				if($model->target_user != null)
					$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);
				
				// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
				if(!isset($_GET['ajax']))
					$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('view', 'id'=>$id));	
			}
		} else 		
			throw new CHttpException(500,'Non captured problem when cancelling the shift change... pls contact michamen@cisco.com !');
	}

	/**
	 * Manages all models.
	 */
	 
	public function actionAdmin()
	{
		$model=new ShiftChange('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['ShiftChange']))
			$model->attributes=$_GET['ShiftChange'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}

	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer $id the ID of the model to be loaded
	 * @return ShiftChange the loaded model
	 * @throws CHttpException
	 */
	public function loadModel($id)
	{
		$model=ShiftChange::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}

	/**
	 * Performs the AJAX validation.
	 * @param ShiftChange $model the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='shift-change-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}

	public function actionManagement()
	{
		$this->sidebarMenu=array(
								array('label'=>'Roster Control', 'url'=>array('/roster/index')),
								array('label'=>'Shift Changes', 'url'=>array('/shiftChange/management')),
								array('label'=>'User Schedules', 'url'=>array('/schedule/index')),
								array('label'=>'Maintenance', 'url'=>array('/site/maintenance')),
								array('label'=>'Reporting', 'url'=>array('/site/reporting')),
							);	
	
		$model=new ShiftChange('search');
		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['ShiftChange']))
			$model->attributes=$_GET['ShiftChange'];
		
		$model->team_id = Yii::app()->user->team_id;
		
		$this->render('management',array(
			'model'=>$model,
		));
	}
	
	public function actionManagementView($id)
	{	
		$this->sidebarMenu=array(
								array('label'=>'Roster Control', 'url'=>array('/roster/index')),
								array('label'=>'Shift Changes', 'url'=>array('/shiftChange/management')),
								array('label'=>'User Schedules', 'url'=>array('/schedule/index')),
								array('label'=>'Maintenance', 'url'=>array('/site/maintenance')),
								array('label'=>'Reporting', 'url'=>array('/site/reporting')),
								
							);		
	
		$this->render('managementView',array(
			'model'=>$this->loadModel($id),
		));
		
	}
	
	public function actionAjaxMembersView($members)
	{
		$membersIds = explode(',', $members);
		$membersModels = array();
		
		foreach($membersIds as $memberId){
			
			//checking for null
			if($memberId != null){
				
				$currentMember = User::model()->findByPk($memberId); //get user model
				
				$membersModels[]= $currentMember; //add to array
								
			}
		}
		
		$this->renderPartial('_membersView', array('models'=> $membersModels));
	}
	
	public function actionApprove($id){
		
		//print_r($_GET);exit;
		
		$model = $this->loadModel($id);
		
		if ($model->request_status == ShiftChange::STATUS_PENDING) {
		
			//Check if Shift requires Accounting approval
			if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
				$model->require_acct_approval = 1;		
		
			$model->request_status = ShiftChange::STATUS_APPROVED;
			$model->comments .= "... Change Approved by " . Yii::app()->user->id;
			
			if(!$model->save(false)){
				//$msg = print_r($model->getErrors(),1);

				
				throw new CHttpException(400,'Error saving data for shift change "Approve" action... contact michamen@cisco.com!');
				
			} else {
			
				//send email notification to requestor
				$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
				
				//send email notification to target_user if present
				if($model->target_user != null)
					$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);				
			
				// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
				if(!isset($_GET['ajax']))
					$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('management'));	
			}
		} else if ($model->request_status == ShiftChange::STATUS_PENDING_CANCEL) {
		
			//Check if Shift requires Accounting approval
			if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
				$model->require_acct_approval = 1;			
				
			$model->request_status = ShiftChange::STATUS_CANCELLED;
			$model->comments .= "... Change Request Cancellation Approved by " . Yii::app()->user->id;
			
			if(!$model->save(false)){
			
			
				throw new CHttpException(400,'Error saving data for shift change "Pending Cancel" to "Cancel" action... contact michamen@cisco.com!');
				
			} else {
				//send email notification to requestor
				$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
				
				//send email notification to target_user if present
				if($model->target_user != null)
					$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);			
			
				// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
				if(!isset($_GET['ajax']))
					$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] :  array('management'));	
			}
		} else 		
			throw new CHttpException(500,'Non captured problem when approving the shift change... pls contact michamen@cisco.com !');
	}	
	
	public function actionDeny($id){
		
		//print_r($_GET);exit;
		
		$model = $this->loadModel($id);
		
		if ($model->request_status == ShiftChange::STATUS_PENDING) {
		
			$model->request_status = ShiftChange::STATUS_DENIED;
			$model->comments .= "... Change Denied by " . Yii::app()->user->id;
			
			if(!$model->save(false)){
				//$msg = print_r($model->getErrors(),1);
				throw new CHttpException(400,'Error saving data for shift change "Deny" action... contact michamen@cisco.com!');
				
			} else {
			

				//send email notification to requestor
				$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
				
				//send email notification to target_user if present
				if($model->target_user != null)
					$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);				
				
				// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
				if(!isset($_GET['ajax']))
					$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('management'));	
			}
		} else if ($model->request_status == ShiftChange::STATUS_PENDING_CANCEL) {
		
			$model->request_status = ShiftChange::STATUS_DENIED;
			$model->comments .= "... Change Request Cancellation Denied by " . Yii::app()->user->id;
			
			if(!$model->save(false)){
			
				throw new CHttpException(400,'Error saving data for shift change "Pending Cancel" to "Denied" action... contact michamen@cisco.com!');
				
			} else {
			
				//send email notification to requestor
				$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
				
				//send email notification to target_user if present
				if($model->target_user != null)
					$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);
			
				// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
				if(!isset($_GET['ajax']))
					$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] :  array('management'));	
			}
		} else if ($model->request_status == ShiftChange::STATUS_APPROVED) {
		
			$model->request_status = ShiftChange::STATUS_DENIED;
			$model->comments .= "... Change Cancelled by " . Yii::app()->user->id;
			
			if(!$model->save(false)){
				//$msg = print_r($model->getErrors(),1);
				throw new CHttpException(400,'Error saving data for shift change "Deny" action when previous state "Approved"... contact michamen@cisco.com!');
				
			} else {
			

				//send email notification to requestor
				$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
				
				//send email notification to target_user if present
				if($model->target_user != null)
					$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);				
				
				// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
				if(!isset($_GET['ajax']))
					$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('management'));	
			}
		} else
			throw new CHttpException(500,'Non captured problem when denying the shift change... pls contact michamen@cisco.com !');
	}		
	
	
	public function actionAjaxEditComments($id, $comments) {
		
		$model = $this->loadModel($id);
		
		$this->renderPartial('_ajaxEditCommentsForm', array('model'=>$model));
	
	}
	
	public function actionAjaxUpdateComments($id)
	{
		//print_r($_POST);	echo "id = $id"; exit;
		
		$model=$this->loadModel($id);

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);
				
		if(isset($_POST['ShiftChange']))
		{
			$model->comments = $_POST['ShiftChange']['comments'];
			
			if($model->save(false))
				$this->redirect(array('managementView','id'=>$model->idshift_change));
			else
				$this->renderPartial('_saveFailed');			
		}
		
		echo "UNCAUGHT FAILURE in ajaxUpdateComments... Please contact michamen@cisco.com";exit;

	}
	
	public function ajaxShowDateSchedule() {

		echo CHtml::ajaxButton ("Refresh",
								CController::createUrl('shiftChange/ajaxShowDateSchedule'), 
								array('update' => '#data')
								);		
		
		
	}

	public function actionChange_Management()
	{
		$this->sidebarMenu=array(
								array('label'=>'My Shifts', 'url'=>array('/shift/my_shifts')),
								array('label'=>'Team Shifts', 'url'=>array('/shift/team_shifts')),
								array('label'=>'Shift Changes', 'url'=>array('/shiftChange/change_management')),
								);		
	
		$model=new ShiftChange('search');
		$model->unsetAttributes();  // clear any default values
		//set the iduser to the current  user logged in
		//$model->iduser = User::model()->findByAttributes(array('username'=>Yii::app()->user->id))->iduser;
		$model->team_id = Yii::app()->user->team_id;

		if(isset($_GET['ShiftChange']))
			$model->attributes=$_GET['ShiftChange'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}
	
	public function actionSwap_Management()
	{
		$this->sidebarMenu=array(
									array('label'=>'Team Q-Shifts', 'url'=>array('/qshift/team_Qshifts' , 'team'=>Yii::app()->user->team_id)),
									array('label'=>'My Q-Shifts', 'url'=>array('/qshift/my_qshifts')),
									array('label'=>'Swap Q-Shift', 'url'=>array('/qshift/swap')),
									array('label'=>'Swap Management', 'url'=>array('/shiftchange/swap_management')),
								);	
	
		$model=new ShiftChange('swapSearch');
		$model->unsetAttributes();  // clear any default values
		// set the iduser to the current  user logged in
		// $model->iduser = User::model()->findByAttributes(array('username'=>Yii::app()->user->id))->iduser;
		$model->team_id = Yii::app()->user->team_id;
		$model->is_swap = 1;

		if(isset($_GET['ShiftChange']))
			$model->attributes=$_GET['ShiftChange'];

		$this->render('swap_management',array(
			'model'=>$model,
		));
	}
	

	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionCancelSwap($id)
	{
		$model = $this->loadModel($id);
		
		if ($model->request_status == ShiftChange::STATUS_APPROVED) {
		
			$model->request_status = ShiftChange::STATUS_CANCELLED;
			$model->comments .= "... Swap Cancelled by " . Yii::app()->user->id;
			
			if(!$model->save(false)){
				//$msg = print_r($model->getErrors(),1);
				throw new CHttpException(400,'Error saving data for Swap cancel action... contact michamen@cisco.com!');
			} else {
			
				//send email notification to requestor
				$this->sendSwapNotification($model->requesting_user,$model->request_status,$model->idshift_change);
				
				//send email notification to target_user if present
				$this->sendSwapNotification($model->target_user,$model->request_status,$model->idshift_change);	
				
				// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
				if(!isset($_GET['ajax']))
					$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('viewSwap', 'id'=>$id));	
			}
		} else 		
			throw new CHttpException(500,'Non captured problem when cancelling the SWAP... pls contact michamen@cisco.com !');
	}

	public function actionReporting()
	{
	
		$this->sidebarMenu=array(
								array('label'=>'Roster Control', 'url'=>array('/roster/index')),
								array('label'=>'Shift Changes', 'url'=>array('/shiftChange/management')),
								array('label'=>'User Schedules', 'url'=>array('/schedule/index')),
								array('label'=>'Maintenance', 'url'=>array('/site/maintenance')),
								array('label'=>'Reporting', 'url'=>array('/site/reporting')),
							);	
							
		$model=new ShiftChange('reportingSearch');
		$model->unsetAttributes();  // clear any default values
		
		$model->team_id = Yii::app()->user->team_id;
		$model->is_swap = 0;
		$model->request_status = 1;
		
		if(isset($_GET['ShiftChange']))
			$model->attributes=$_GET['ShiftChange'];
			
		if ($this->isExportRequest()) {
					//set_time_limit(0); //Uncomment to export lage datasets
					//Add to the csv a single line of text
					//$this->exportCSV(array('RESULTS WITH FILTER:'), null, false);
					//Add to the csv a single model data with 3 empty rows after the data
					//$this->exportCSV($model, array_keys($model->attributeLabels()), false, 3);
					//Add to the csv a lot of models from a CDataProvider
					$this->exportCSV($model->reportingSearch(), array('requestingUser_relation.username', 
															 'currentShift_relation.name', 
															 'requestedShift_relation.name', 
															 'requestedQshift_relation.name',
															 'day_requested',
															 'targetUser',
															 'yesNoValue',
															 'statusValue',															 
															 )
									);
		}		
		
		$this->render('reporting',array(
			'model'=>$model,
		));
	}

	
	public function actionViewSwap($id)
	{
		$this->render('viewSwap',array(
			'model'=>$this->loadModel($id),
		));
	}
		
	public function sendShiftChangeNotification($toUser,$status,$shiftChange)
	{
	
		//BYPASS EMAIL SENDING HERE
		return true;
		
		$userModel = User::model()->findByPk($toUser);
		
		if($userModel == null) {
			return false;
		}
		
		$newStatus = ShiftChange::getStatus($status);
		
		$content = "<font color=blue><b><h3> Shift Change Status Notification </h3></b></font>
					<font color=black><b> Hello ".$userModel->fullname.", <br><br> The status of one of your opened Shift Change requests has changed to <span style='color:red;font-weight:bold;'>"
					.$newStatus.
					"</span></b>
					<br><br>
					To see it, click "
					. CHtml::link(CHtml::encode('here'), array('http://10.198.28.163/staffer/index.php/shiftChange', 'id'=>$shiftChange)) .					
					"</font>
					<br>
					<h5> Please don't reply to this email... cuz no one will read it :-P</h5>
					";
								
		// Plain text content
		$plainTextContent = "STAFFer Shift Change Status Notification \n
							 \n
							 Hello ".$userModel->fullname.", \n
							 The status of one of your Shift Change requests has changed to \"".$newStatus."\"\n
							 \n
							 Please visit the STAFFer tool and go to \"Shifts/Shift Changes\" for more details \n
							 \n
							 Please don't reply to this email... cuz no one will read it :-P";
		
		// Get mailer
		$SM = Yii::app()->swiftMailer;								
		
		// Get config
		$mailHost = 'smtp.gmail.com';
		$mailPort = 465; // Optional

		// New transport
		$Transport = $SM->smtpTransport($mailHost, $mailPort);
	 
		// Mailer
		$Mailer = $SM->mailer($Transport);
	 
		// New message
		$Message = $SM
			->newMessage('STAFFer Notification')
			->setFrom(array('cr.tac.staffer@gmail.com' => 'CR-TAC STAFFer'))
			->setTo(array($userModel->email => $userModel->fullname))	
			->addPart($content, 'text/html')
			->setBody($plainTextContent);
	 
		// Send mail
		$result = $Mailer->send($Message);		
		
		/*
		if($result){
			echo "EMAIL SENT";exit;
		} else {
			echo "FAILED TO SEND EMAIL";exit;
		}
		*/
		
		return $result;
		
		//$this->render('index');
	}

	public function sendSwapNotification($toUser,$status,$shiftChange)
	{
		//BYPASS EMAIL SENDING HERE
		return true;
		
		$userModel = User::model()->findByPk($toUser);
		
		if($userModel == null) {
			return false;
		}
		
		$newStatus = ShiftChange::getStatus($status);
		
		$content = "<font color=blue><b><h3> Q-Shift SWAP Status Notification </h3></b></font>
					<font color=black><b> Hello ".$userModel->fullname.", <br><br> The status of one of your opened Q-Shift SWAPs has changed to <span style='color:red;font-weight:bold;'>"
					.$newStatus.
					"</span></b>
					<br><br>
					To see it, click "
					. CHtml::link(CHtml::encode('here'), array('http://10.198.28.163/staffer/index.php/shiftChange', 'id'=>$shiftChange)) .					
					"</font><br>
					<h5> Please don't reply to this email... cuz no one will read it :-P</h5>
					";
								
		// Plain text content
		$plainTextContent = "STAFFer Q-Shift SWAP Status Notification \n
							 \n
							 Hello ".$userModel->fullname.", \n
							 The status of one of your Shift Change requests has changed to \"".$newStatus."\"\n
							 \n
							 Please visit the STAFFer tool and go to \"Q-Shifts/Swap Management\" for more details \n
							 \n
							 Please don't reply to this email... cuz no one will read it :-P";
		
		// Get mailer
		$SM = Yii::app()->swiftMailer;								
		
		// Get config
		$mailHost = 'smtp.gmail.com';
		$mailPort = 465; // Optional

		// New transport
		$Transport = $SM->smtpTransport($mailHost, $mailPort);
	 
		// Mailer
		$Mailer = $SM->mailer($Transport);
	 
		// New message
		$Message = $SM
			->newMessage('STAFFer Notification')
			->setFrom(array('cr.tac.staffer@gmail.com' => 'CR-TAC STAFFer'))
			->setTo(array($userModel->email => $userModel->fullname))	
			->addPart($content, 'text/html')
			->setBody($plainTextContent);
	 
		// Send mail
		$result = $Mailer->send($Message);		
		
		return $result;
		
		//$this->render('index');
	}
	
	public function actionAjaxRosterCreate($user,$date){
	
		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);
		
		//echo "Entering only with user $user and date $date";exit;
				
		$model= new ShiftChange;
		
		$userModel =  User::model()->findByPk($user);
		
		$model->day_requested = $date;
		$model->requesting_user = $userModel->iduser;
		$model->team_id = $userModel->team;
		$model->request_status = ShiftChange::STATUS_PENDING;

		if(isset($_POST['ShiftChange']))
		{
			$model->attributes=$_POST['ShiftChange'];		
			
			$currentShift = Schedule::getUserScheduleForDate($model->requesting_user, $model->day_requested);
			
			if($currentShift!=null)
				$model->current_shift = $currentShift->idshift;
			
			print_r($_POST); 
			
			if(isset($_POST['choice']) and ($_POST['choice'] == 'radioToShift')) {

				// start active shift change check
				$criteria=new CDbCriteria;
				$criteria->condition = "day_requested like '".$model->day_requested."' \n
										and (request_status <> ". ShiftChange::STATUS_CANCELLED ." and request_status <> ". ShiftChange::STATUS_DENIED.") \n
										and (requesting_user = '".$model->requesting_user."')";			
				
				$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
				
				//print_r($shiftChangeResult);exit;
				
				// checking if user already has shift change pending or approved for this day
				if ($shiftChangeResult!=null) {
					$model->addError('requested_shift','You already have a change pending or approved for this day, only one allowed!');
					$this->renderPartial('_ajaxRosterCreate',array(
										 'model'=>$model,
										 false,
										 true
										));					
				} else {			
				
					//Check if Shift requires Accounting approval
					if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
						$model->require_acct_approval = 1;				
				
					$model->target_user = null;
					$model->request_status = ShiftChange::STATUS_APPROVED;
					$model->comments .= "... Change Created and Approved by " . Yii::app()->user->id;
					
					//all checks passed, save!
					if($model->save()){
						
						//send email notification to requestor
						$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
						
						//send email notification to target_user if present
						if($model->target_user != null)
							$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);						
						
						$this->renderPartial('shortView', array('model'=>$model),false,true);
						
					} else {
						$model->addError('day_requested','Error saving!');
					
						$this->renderPartial('_ajaxRosterCreate',array(
											 'model'=>$model,
											 false,
											 true
											));		
					}
				}			
			
			} else if(isset($_POST['choice']) and ($_POST['choice'] == 'radioToUser') ) {
			
				if( empty($_POST['ShiftChange']['target_user']) ) {
					$model->addError('target_user','A "Target User" must be selected if the "Change with User" option is used!');	
					
					$this->renderPartial('_ajaxRosterCreate',array(
										 'model'=>$model,
										 false,
										 true
										));							
				} else {

					// start active shift change check
					$criteria=new CDbCriteria;
					$criteria->condition = "day_requested like '".$model->day_requested."' \n
											and (request_status <> ". ShiftChange::STATUS_CANCELLED ." and request_status <> ". ShiftChange::STATUS_DENIED.") \n
											and (requesting_user = '".$model->requesting_user."' or target_user = '".$model->requesting_user."'
												or requesting_user = '".$model->target_user."' or target_user = '".$model->target_user."')";			
					
					$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
					
					// checking if user already has shift change pending or approved for this day
					if ($shiftChangeResult!=null) {
						$model->addError('day_requested','You, or the target user, already have a change pending or approved for this day, 
															and only one allowed per user per day!');
					$this->renderPartial('_ajaxRosterCreate',array(
										 'model'=>$model,
										 false,
										 true
										));					
					} else {	
					
						//Check if Shift requires Accounting approval
						if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
							$model->require_acct_approval = 1;						
						
						//all checks passed, save!
						$model->request_status = ShiftChange::STATUS_APPROVED;
						$model->comments .= "... Change Created and Approved by " . Yii::app()->user->id;						
												
						if($model->save()){
							
							
							//send email notification to requestor
							$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
							
							//send email notification to target_user if present
							if($model->target_user != null)
								$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);
							
							$this->renderPartial('shortView', array('model'=>$model),false,true);
						
						} else {
							$model->addError('day_requested','Error saving with target user!');
						
						$this->renderPartial('_ajaxRosterCreate',array(
											 'model'=>$model,
											 false,
											 true
											));		
						}
					}
				}
			} else
				echo "NO IF MATCHED!"; exit;
			
		}
		
		$this->renderPartial('_ajaxRosterCreate',array('model'=>$model),false,true);	
		
	}

	
	public function actionRosterCreate($user,$date){
	
		// Uncomment the following line if AJAX validation is needed
		//$this->performAjaxValidation($model);
		
		$this->sidebarMenu=array(
								array('label'=>'Shift Changes', 'url'=>array('/shiftChange/management')),
								array('label'=>'User Schedules', 'url'=>array('/schedule/index')),
								array('label'=>'Maintenance', 'url'=>array('/site/maintenance')),
								array('label'=>'Reporting', 'url'=>array('/site/reporting')),
							);
		
		$model= new ShiftChange;
		
		$userModel =  User::model()->findByPk($user);
		
		$model->day_requested = $date;
		$model->requesting_user = $userModel->iduser;
		$model->team_id = $userModel->team;
		$model->request_status = ShiftChange::STATUS_PENDING;
		
		if(isset($_POST['ShiftChange']))
		{
			$model->attributes=$_POST['ShiftChange'];		
			
			$currentShift = Schedule::getUserScheduleForDate($model->requesting_user, $model->day_requested);
			
			if($currentShift!=null)
				$model->current_shift = $currentShift->idshift;
			
			//print_r($_POST); 
			
			if(isset($_POST['choice']) and ($_POST['choice'] == 'radioToShift')) {

				// start active shift change check
				$criteria=new CDbCriteria;
				$criteria->condition = "day_requested like '".$model->day_requested."' \n
										and (request_status <> ". ShiftChange::STATUS_CANCELLED ." and request_status <> ". ShiftChange::STATUS_DENIED.") \n
										and (requesting_user = '".$model->requesting_user."')";			
				
				$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
				
				//print_r($shiftChangeResult);exit;
				
				// checking if user already has shift change pending or approved for this day
				if ($shiftChangeResult!=null) {
					$model->addError('requested_shift','There\'s already a pending or approved change for this day, only one is allowed!');
					$this->render('rosterCreate',array(
										 'model'=>$model,
										 false,
										 true
										));					
				} else {			
				
					$model->target_user = null;
					$model->request_status = ShiftChange::STATUS_APPROVED;
					$model->comments .= "... Change Created and Approved by " . Yii::app()->user->id;
					
					//Check if Shift requires Accounting approval
					if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
						$model->require_acct_approval = 1;					
					
					//all checks passed, save!
					if($model->save()){
						
						//send email notification to requestor
						$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
						
						//send email notification to target_user if present
						if($model->target_user != null)
							$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);						
						
						$dateArray = explode('-',$date);
						$dateObject = new DateTime('NOW');
						$dateObject->setTimeZone(new DateTimeZone("America/Costa_Rica"));
						$dateObject->setDate($dateArray[0],$dateArray[1],$dateArray[2]);
						$week= $dateObject->format('W');
						$year= $dateObject->format('o');						
						
						Yii::app()->user->setFlash('success', "Shift Change Saved Successfully!");
						
						$this->redirect(array('roster/index', 'week'=>$week,'year'=>$year));
						
					} else {
						$model->addError('day_requested','Error saving!');
					
						$this->render('rosterCreate',array(
											 'model'=>$model,
											 false,
											 true
											));		
					}
				}			
			
			} else if(isset($_POST['choice']) and ($_POST['choice'] == 'radioToUser') ) {
			
				if( empty($_POST['ShiftChange']['target_user']) ) {
					$model->addError('target_user','A "Target User" must be selected if the "Change with User" option is used!');	
					
					$this->render('rosterCreate',array(
										 'model'=>$model,
										 false,
										 true
										));							
				} else {

					// start active shift change check
					$criteria=new CDbCriteria;
					$criteria->condition = "day_requested like '".$model->day_requested."' \n
											and (request_status <> ". ShiftChange::STATUS_CANCELLED ." and request_status <> ". ShiftChange::STATUS_DENIED.") \n
											and (requesting_user = '".$model->requesting_user."' or target_user = '".$model->requesting_user."'
												or requesting_user = '".$model->target_user."' or target_user = '".$model->target_user."')";			
					
					$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
					
					// checking if user already has shift change pending or approved for this day
					if ($shiftChangeResult!=null) {
						$model->addError('day_requested','This user, or the target user, already has a change pending or approved for this day, 
															and only one allowed per user per day!');
					$this->render('rosterCreate',array(
										 'model'=>$model,
										 false,
										 true
										));					
					} else {	
					
						//Check if Shift requires Accounting approval
						if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
							$model->require_acct_approval = 1;						
							
						//all checks passed, save!
						$model->request_status = ShiftChange::STATUS_APPROVED;
						$model->comments .= "... Change Created and Approved by " . Yii::app()->user->id;						
						
						if($model->save()){
							
							
							//send email notification to requestor
							$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
							
							//send email notification to target_user if present
							if($model->target_user != null)
								$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);
							
							$dateArray = explode('-',$date);
							$dateObject = new DateTime('NOW');
							$dateObject->setTimeZone(new DateTimeZone("America/Costa_Rica"));
							$dateObject->setDate($dateArray[0],$dateArray[1],$dateArray[2]);
							$week= $dateObject->format('W');
							$year= $dateObject->format('o');						
							
							Yii::app()->user->setFlash('success', "Shift Change Saved Successfully!");
							
							$this->redirect(array('roster/index', 'week'=>$week,'year'=>$year));
						
						} else {
							$model->addError('day_requested','Error saving with target user!');
						
						$this->render('rosterCreate',array(
											 'model'=>$model,
											 false,
											 true
											));		
						}
					}
				}
			} else
				echo "NO IF MATCHED!!!.. this is an error, please contact michamen@cisco.com"; exit;
			
		}
		
		$this->render('rosterCreate',array('model'=>$model),false,true);	
		
	}	
	
	
	public function actionRosterCreateEmpty($user,$date){
	
		// Uncomment the following line if AJAX validation is needed
		//$this->performAjaxValidation($model);
		
		$this->sidebarMenu=array(
								array('label'=>'Shift Changes', 'url'=>array('/shiftChange/management')),
								array('label'=>'User Schedules', 'url'=>array('/schedule/index')),
								array('label'=>'Maintenance', 'url'=>array('/site/maintenance')),
								array('label'=>'Reporting', 'url'=>array('/site/reporting')),
							);
		
		$model= new ShiftChange;
		
		$userModel =  User::model()->findByPk($user);
		
		$model->day_requested = $date;
		$model->requesting_user = $userModel->iduser;
		$model->team_id = $userModel->team;
		$model->request_status = ShiftChange::STATUS_PENDING;

		if(isset($_POST['ShiftChange']))
		{
			$model->attributes=$_POST['ShiftChange'];		
			
			$currentShift = Schedule::getUserScheduleForDate($model->requesting_user, $model->day_requested);
			
			if($currentShift!=null)
				$model->current_shift = $currentShift->idshift;
			
			print_r($_POST); 
			
			if(isset($_POST['choice']) and ($_POST['choice'] == 'radioToShift')) {

				// start active shift change check
				$criteria=new CDbCriteria;
				$criteria->condition = "day_requested like '".$model->day_requested."' \n
										and (request_status <> ". ShiftChange::STATUS_CANCELLED ." and request_status <> ". ShiftChange::STATUS_DENIED.") \n
										and (requesting_user = '".$model->requesting_user."')";			
				
				$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
				
				//print_r($shiftChangeResult);exit;
				
				// checking if user already has shift change pending or approved for this day
				if ($shiftChangeResult!=null) {
					$model->addError('requested_shift','There\'s already a pending or approved change for this day, only one is allowed!');
					$this->render('rosterCreateEmpty',array(
										 'model'=>$model,
										 false,
										 true
										));					
				} else {			
					$model->target_user = null;
					$model->request_status = ShiftChange::STATUS_APPROVED;
					$model->comments .= "... Change Created and Approved by " . Yii::app()->user->id;
					
					//Check if Shift requires Accounting approval
					if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
						$model->require_acct_approval = 1;					
					
					//all checks passed, save!
					if($model->save()){
						
						//send email notification to requestor
						$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
						
						//send email notification to target_user if present
						if($model->target_user != null)
							$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);						
						
						$dateArray = explode('-',$date);
						$dateObject = new DateTime('NOW');
						$dateObject->setTimeZone(new DateTimeZone("America/Costa_Rica"));
						$dateObject->setDate($dateArray[0],$dateArray[1],$dateArray[2]);
						$week= $dateObject->format('W');
						$year= $dateObject->format('o');						
						
						Yii::app()->user->setFlash('success', "Shift Change Saved Successfully!");
						
						$this->redirect(array('roster/index', 'week'=>$week,'year'=>$year));
						
					} else {
						$model->addError('day_requested','Error saving!');
					
						$this->render('rosterCreateEmpty',array(
											 'model'=>$model,
											 false,
											 true
											));		
					}
				}			
			
			} else if(isset($_POST['choice']) and ($_POST['choice'] == 'radioToUser') ) {
			
				if( empty($_POST['ShiftChange']['target_user']) ) {
					$model->addError('target_user','A "Target User" must be selected if the "Change with User" option is used!');	
					
					$this->render('rosterCreateEmpty',array(
										 'model'=>$model,
										 false,
										 true
										));							
				} else {

					// start active shift change check
					$criteria=new CDbCriteria;
					$criteria->condition = "day_requested like '".$model->day_requested."' \n
											and (request_status <> ". ShiftChange::STATUS_CANCELLED ." and request_status <> ". ShiftChange::STATUS_DENIED.") \n
											and (requesting_user = '".$model->requesting_user."' or target_user = '".$model->requesting_user."'
												or requesting_user = '".$model->target_user."' or target_user = '".$model->target_user."')";			
					
					$shiftChangeResult = ShiftChange::model()->findAll($criteria);		
					
					// checking if user already has shift change pending or approved for this day
					if ($shiftChangeResult!=null) {
						$model->addError('day_requested','This user, or the target user, already has a change pending or approved for this day, 
															and only one allowed per user per day!');
					$this->render('rosterCreateEmpty',array(
										 'model'=>$model,
										 false,
										 true
										));					
					} else {	

					//Check if Shift requires Accounting approval
						if(Shift::model()->findByPk($model->requested_shift)->require_acct_approval == 1)
							$model->require_acct_approval = 1;						
					
						//all checks passed, save!
						$model->request_status = ShiftChange::STATUS_APPROVED;
						$model->comments .= "... Change Created and Approved by " . Yii::app()->user->id;						
						
						if($model->save()){
							
							
							//send email notification to requestor
							$this->sendShiftChangeNotification($model->requesting_user,$model->request_status,$model->idshift_change);
							
							//send email notification to target_user if present
							if($model->target_user != null)
								$this->sendShiftChangeNotification($model->target_user,$model->request_status,$model->idshift_change);
							
							$dateArray = explode('-',$date);
							$dateObject = new DateTime('NOW');
							$dateObject->setTimeZone(new DateTimeZone("America/Costa_Rica"));
							$dateObject->setDate($dateArray[0],$dateArray[1],$dateArray[2]);
							$week= $dateObject->format('W');
							$year= $dateObject->format('o');						
							
							Yii::app()->user->setFlash('success', "Shift Change Saved Successfully!");
							
							$this->redirect(array('roster/index', 'week'=>$week,'year'=>$year));
						
						} else {
							$model->addError('day_requested','Error saving with target user!');
						
						$this->render('rosterCreateEmpty',array(
											 'model'=>$model,
											 false,
											 true
											));		
						}
					}
				}
			} else
				echo "NO IF MATCHED!!!.. this is an error, please contact michamen@cisco.com"; exit;
			
		}
		
		$this->render('rosterCreateEmpty',array('model'=>$model),false,true);	
		
	}	

	public function actionAccountingApprovals()
	{
		$this->sidebarMenu=array(
								array('label'=>'Roster Control', 'url'=>array('/roster/index')),
								array('label'=>'Shift Changes', 'url'=>array('/shiftChange/management')),
								array('label'=>'User Schedules', 'url'=>array('/schedule/index')),
								array('label'=>'Maintenance', 'url'=>array('/site/maintenance')),
								array('label'=>'Reporting', 'url'=>array('/site/reporting')),
							);	
	
		$model=new ShiftChange('search');
		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['ShiftChange']))
			$model->attributes=$_GET['ShiftChange'];
		
		$model->team_id = Yii::app()->user->team_id;
		
		$this->render('accountingApprovals',array(
			'model'=>$model,
		));
	}

	public function actionAccountingApprove($id){
		
		//print_r($_GET);exit;
		
		$model = $this->loadModel($id);
		
		if (($model!=null) and ($model->accounting_approved != 1)) {
		
			$model->accounting_approved = 1;
			
			if(!$model->save(false)){
				//$msg = print_r($model->getErrors(),1);
				throw new CHttpException(400,'Error saving data for shift change "Account Approve" action... contact michamen@cisco.com!');
				
			} 
		}
	}		
	
	
}

